package com.yhny.lykj.yuhannongye.Adapter;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.longsichao.lscframe.view.LSCImageView;
import com.yhny.lykj.yuhannongye.R;
import com.yhny.lykj.yuhannongye.app.BaseRefreshListAdapter;
import com.yhny.lykj.yuhannongye.model.OrderCommentListModel;

import java.util.List;

/**
 * OrderListAdapter
 * 订单列表 待评价
 */
public class OrderCommentListAdapter extends BaseRefreshListAdapter<OrderCommentListAdapter.ViewHolder> {
    private List<OrderCommentListModel.ListEntity> list;
    private OnItemClickListener listener = null;
    private Context context;

    public OrderCommentListAdapter(List<OrderCommentListModel.ListEntity> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    protected void onBindBaseViewHolder(ViewHolder holder, int position) {
        final OrderCommentListModel.ListEntity entity = list.get(position);
        Resources resources = holder.imageView1.getContext().getResources();
        int height = resources.getDimensionPixelOffset(R.dimen.item_order_small_width);
        int width = resources.getDimensionPixelOffset(R.dimen.item_order_small_width);
        String imageUrl1 = entity.goods_img;


        if (imageUrl1 == null) {
            imageUrl1 = "";
        }
        if (!TextUtils.isEmpty(imageUrl1)) {
            holder.imageView1.setPlaceHolder(R.drawable.normal_pic).setTargetSize(width, height).setImageURI(Uri.parse(imageUrl1));
        }else{
            holder.imageView1.setPlaceHolder(R.drawable.normal_pic);
        }

        holder.shopTv.setText(entity.order_id);
//        holder.typeTv.setText("共"+entity.goods_nums+"件商品，合计：");
        holder.titleView.setText(entity.goods_name);
        holder.item_market.setText(entity.money_price);
        holder.item_price.setText(entity.integral_price);
        holder.item_zhi.setText("");

            holder.numView.setText("X "+entity.goods_nums);
        int pos = position;
        holder.commentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //立即评价
//                Intent intent = new Intent(context, OrderCommentActivity.class);
//                intent.putExtra(ORDER_ID,entity.order_id);
//                intent.putExtra(SHOP_ID,entity.goods_id);
//                intent.putExtra(FROM_TYPE_ID,FROM_TYPE_VIEW_ORDER_LIST);
//                context.startActivity(intent);
            }
        });
    }

    @Override
    protected int getLayoutResId(int viewType) {

        return R.layout.item_order_comment_list;
    }

    @Override
    protected ViewHolder onCreateBaseViewHolder(View itemView) {
        return new ViewHolder(itemView, listener);
    }

    public static class ViewHolder extends BaseRefreshListAdapter.ViewHolder {

        private TextView shopTv;
        private TextView titleView;
        private TextView typeTv;
        private TextView item_price;
        private Button commentView;
        private TextView numView;
        private TextView item_zhi;
        private TextView item_market;
        private LSCImageView imageView1;

        public ViewHolder(View itemView, OnItemClickListener listener) {
            super(itemView, listener);
            imageView1 = (LSCImageView) itemView.findViewById(R.id.item_img1);

            shopTv = (TextView) itemView.findViewById(R.id.item_shop);
            item_market = (TextView) itemView.findViewById(R.id.item_market);
            item_price = (TextView) itemView.findViewById(R.id.item_price);
            numView = (TextView) itemView.findViewById(R.id.item_num);
            item_zhi = (TextView) itemView.findViewById(R.id.item_zhi);
            titleView = (TextView) itemView.findViewById(R.id.item_title);
            typeTv = (TextView) itemView.findViewById(R.id.item_type);
            commentView = (Button) itemView.findViewById(R.id.oder_comment);
        }

    }
}
